﻿#ifndef __OBJECT_H__
#define __OBJECT_H__

#include "miniui/minitype.h"
#include "miniui/minitypes.h"
#include "event/event.h"

namespace MiniUI
{

class Object;

typedef void (Delegater::*OnNotifyEventFunc)(const Object* sender);

class Object
{
protected:
    Object(const char* szType = "");
    virtual ~Object();
public:
    int AddRef();
    int Release();
public:
    const char* GetType() const;
    bool CheckType(const char* szType) const;
protected:
    const char* const m_szType;
    int m_ref;
};

template <class T>
class Creator
{
public:
    static T* CreateInstance()
    {
        return new T;
    }
};

template <class T>
class TypeObject
{
public:
    static const char* GetTypeName()
    {
        return s_szTypeName;
    }
private:
    static const char* s_szTypeName;
};

template <class T, class TBase>
class DeriveUIObject : public TBase
{
protected:
    DeriveUIObject() : TBase(GetTypeName()){}
public:
    static T* CreateInstance()
    {
        return new T;
    }
    static const char* GetTypeName()
    {
        return s_szTypeName;
    }
private:
    static const char* s_szTypeName;
};

class ObjectGuard
{
public:
    ObjectGuard(const Object* pObj);
    ~ObjectGuard();
protected:
    Object* m_pObj;
};

}

#endif